Xbasic

NOW Function

Syntax

Date_Time as T = NOW([L gmt_time])

Arguments

gmt_timeLogical

Default = .F. If flag is .T., then the time is returned as GMT. If flag is .F., time is returned as the local system time.

Returns

Date_TimeTime

Returns the current date and time as a time data type.

Description

Returns the current time. The time can be returned as either local time (default) or GMT.

Discussion

NOW() returns the current date and time, correct to the millisecond, in the Time data type. The time can be returned as either local time or GMT time.

If used in a web application and the local time is returned, the time will be calculated using the web application server's system time.

? now()
= 01/16/2003 10:24:51 09 am

' Return time as GMT
? now(.T.)
= 01/16/2003 03:24:51 09 pm

dim t1 as T
dim t2 as T
t1 = now()
t2 = now()

? t2-t1 
= 5.440000

Comparing NOW() with TIME()

Both the NOW() and TIME() function will return the current time. The difference between the two methods is that NOW() returns the current time as a time type while TIME() returns a character string. As a result, if you try to assign the value returned by the TIME() function into a time variable, a "variable type mismatch" error will occur:

dim t3 as T

' the following assignment will cause an error because the time function
' returns a character string, not a time value:
t3 = time()
ERROR: variable type mismatch

The TIME() function also does not return millisecond.

The TIME() function can also be used to format an existing time value. For example:

? time("MM/dd/yyyy 0h:0m:0s 2 am", now(.T.))
= "01/16/2003 03:24:51 09 pm"

See Also